<?php
require( 'php/database.php' );
require( 'config.php' );

//
if ( isset( $_GET[ 'id' ] ) ) {
    $iProductId = $_GET[ 'id' ];
} else {
    $iProductId = 0;
}

if ( isset( $_GET[ 'source' ] ) ) {
    $sSource = $_GET[ 'source' ];
} else {
    $sSource = 'browse.php';
}

//
$oDB = new Database( $g_sMySqlServer,
                     $g_sMySqlUsername,
                     $g_sMySqlPassword,
                     $g_sMySqlDatabase );

//
if ( $iProductId != 0 ) {
    //
    $sSQL  = "DELETE FROM products WHERE product_id = ${iProductId}";

    $oDB->execute( $sSQL );

    //
    $sSQL  = "DELETE FROM messages WHERE product_id = ${iProductId}";

    $oDB->execute( $sSQL );
        
    //
    $iResult = 100;
} else {
    //
    $iResult = 101;
}

// Redirect to a different page in the current directory that was requested
$sHost  = $_SERVER[ 'HTTP_HOST' ];
$sUri   = rtrim( dirname( $_SERVER[ 'PHP_SELF' ] ), '/\\' );
$sExtra = "${sSource}?result=${iResult}";
header( "Location: http://${sHost}${sUri}/${sExtra}" );
?>
